﻿
    function loadSystem(count)
    {
        if (document.getElementById("DR_" + count).value!= "-- Select System Variables --")
            document.getElementById("paramTB" + count).value="{!" + document.getElementById("DR_" + count).value + "}";
    }
    // Added by John Sathish
    function ddlEnableDisable(id)
    {
        if ( document.getElementById("ctl00_ContentPlaceHolder3_cbx"+id+"Email").checked)
            document.getElementById("ctl00_ContentPlaceHolder3_ddl"+id+"Email").disabled = false;
        else
            document.getElementById("ctl00_ContentPlaceHolder3_ddl"+id+"Email").disabled = true;
    }
    //Up to this
   
    var showMode = false; var timer;
     //implemented by sanal on Feb 25, 2008
    var myWidth = 0;
    var myHeight = 0;
    var scrOfX = 0;
    var scrOfY = 0;
    var browserNetScape=false;    
    function setVariables()
    {  
     if (navigator.appName == "Netscape")  	 
  	    browserNetScape = true;
    }
    function loadthis()
    {
        setVariables();
    }
    function setWindowSize() {
      //var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
      //window.alert( 'Width = ' + myWidth );
      //window.alert( 'Height = ' + myHeight );
    }
    function getScrollXY() {      
      if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
      //return [ scrOfX, scrOfY ];
    }
    function close1()
    {
        showMode = false;
        document.getElementById("Panel1").style.display = "none";
        document.getElementById("div_cont").style.display = "none";
        clearTimeout(timer);
        makeDropDownVisible();
    }
    
    function open1()
    {
        setVariables();        
        showMode = true;
        setWindowSize();
        getScrollXY();
        document.getElementById("Panel1").style.display = "block";
        //document.getElementById("Panel1").style.visibility = "visible";  
        document.getElementById("div_cont").style.display = "block";
        //document.getElementById("pnlContent").style.visibility = "visible";        
        if (browserNetScape == true) 
        {  
            document.getElementById("Panel1").style.width='';
            document.getElementById("Panel1").style.left='';
            document.getElementById("Panel1").style.top='';
            document.getElementById("Panel1").style.height='';
            document.getElementById("Panel1").style.left="0px";
            document.getElementById("Panel1").style.top="0px";
            document.getElementById("Panel1").style.width= (myWidth+ scrOfX-8) + "px";
            document.getElementById("Panel1").style.height = (myHeight+ scrOfY-8) + "px";
            var lef = ((myWidth-document.getElementById("div_cont").offsetWidth)/2);
            var top = (myHeight-document.getElementById("div_cont").offsetHeight)/2 + scrOfY;
            document.getElementById("div_cont").style.left = lef + "px" ;
            document.getElementById("div_cont").style.top = top + "px";
        }
        else
        {
            document.getElementById("Panel1").style.left="0";
            document.getElementById("Panel1").style.top="0";
            document.getElementById("Panel1").style.width= myWidth + scrOfX;
            document.getElementById("Panel1").style.height = myHeight + scrOfY;
            document.getElementById("div_cont").style.left = (myWidth-document.getElementById("div_cont").offsetWidth)/2;
            //document.getElementById("div_cont").style.top = "0";
            document.getElementById("div_cont").style.top = (myHeight-document.getElementById("div_cont").offsetHeight)/2;
        }
        if (showMode==true) timer = setTimeout("open1()",300);        
        //return false;
    }    
    function EditRules(strValue,rowCount)
    {
        try
        {
            makeDropDownInvisible();
            document.getElementById("validateSpan").innerHTML = "";
            document.getElementById("ctl00_ContentPlaceHolder3_hfRule_Af_row_id").value = document.getElementById("ctl00_ContentPlaceHolder3_af_row_id" + rowCount).value;
            document.getElementById("ctl00_ContentPlaceHolder3_txtRuleName").value = document.getElementById("ctl00_ContentPlaceHolder3_RuleName" + rowCount).innerHTML;
            
            var splitTitle = document.getElementById("ctl00_ContentPlaceHolder3_hf_Title").value.split(",");
            document.getElementById("selTargetTitle").options[0] = new Option("--Select a title--","");
            for(iCount = 1; iCount < splitTitle.length ; iCount++)
            {
                document.getElementById("selTargetTitle").options[iCount] = new Option(splitTitle[iCount - 1],iCount);
            }

            /*if (rowCount != "0")
            {
                //document.getElementById("rdField").disabled = false;
                document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceTitle").disabled=true;
            }*/
            
            /*if (document.getElementById("ctl00_ContentPlaceHolder3_Target" + rowCount).innerHTML == "title")
            {
                SelectTarget("rdTitle");
            }
            else */
            document.getElementById("ctl00_ContentPlaceHolder3_hf_Target").value = "title";
            
            document.getElementById("rdTitle").checked = true;
            document.getElementById("rdUser").checked = false;
            document.getElementById("rdField").checked = false;
                
            if (document.getElementById("ctl00_ContentPlaceHolder3_Target" + rowCount).value == "user")
            {
                document.getElementById("ctl00_ContentPlaceHolder3_hf_Target").value = "user";
                SelectTarget("rdUser");
            }
            else if (document.getElementById("ctl00_ContentPlaceHolder3_Target" + rowCount).value == "user_from_field")
            {
                document.getElementById("ctl00_ContentPlaceHolder3_hf_Target").value = "user_From_field";
                SelectTarget("rdField");
            }
            if (document.getElementById("ctl00_ContentPlaceHolder3_ddlbased_on").value == "Title")
            {
                /*if (rowCount != "0")
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceTitle").disabled=true;*/
                if (document.getElementById("ctl00_ContentPlaceHolder3_SourceTitle" + rowCount).innerHTML == "")
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceTitle").selectedIndex = 0;
                else
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceTitle").value = document.getElementById("ctl00_ContentPlaceHolder3_SourceTitle" + rowCount).innerHTML;
                for(iCount = 0; iCount < document.getElementById("selTargetTitle").options.length; iCount++)
                {
                    if (document.getElementById("selTargetTitle").options[iCount].text == document.getElementById("ctl00_ContentPlaceHolder3_TargetTitle" + rowCount).innerHTML)
                        document.getElementById("selTargetTitle").options[iCount].selected = true;
                }
                //document.getElementById("rdUser").disabled = true;
            }
            else if (document.getElementById("ctl00_ContentPlaceHolder3_ddlbased_on").value == "User")
            {
                /*if (rowCount != "0")
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceUser").disabled=true;*/

                if (document.getElementById("ctl00_ContentPlaceHolder3_SourceTitle" + rowCount).innerHTML == "")
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceUser").selectedIndex = 0;
                else
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceUser").value = document.getElementById("ctl00_ContentPlaceHolder3_SourceTitle" + rowCount).innerHTML;
                //document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceUser").value = document.getElementById("ctl00_ContentPlaceHolder3_SourceTitle" + rowCount).innerHTML;
                for(iCount = 0; iCount < document.getElementById("selTargetTitle").options.length; iCount++)
                {
                    if (document.getElementById("selTargetTitle").options[iCount].text == document.getElementById("ctl00_ContentPlaceHolder3_TargetTitle" + rowCount).innerHTML)
                        document.getElementById("selTargetTitle").options[iCount].selected = true;
                }
                //document.getElementById("rdTitle").disabled = true;
                //document.getElementById("rdField").disabled = true;
            }
            document.getElementById("ctl00_ContentPlaceHolder3_txtWI_Message").value = document.getElementById("ctl00_ContentPlaceHolder3_WI_Message" + rowCount).value;
            document.getElementById("ctl00_ContentPlaceHolder3_txtFieldValue").value = document.getElementById("ctl00_ContentPlaceHolder3_FieldUpdateValue" + rowCount).value;
            document.getElementById("ctl00_ContentPlaceHolder3_chkAddWI").checked = document.getElementById("ctl00_ContentPlaceHolder3_AddWorkItem" + rowCount).value.toLowerCase() == "true";
            document.getElementById("ctl00_ContentPlaceHolder3_chkFieldUpdate").checked = document.getElementById("ctl00_ContentPlaceHolder3_addFieldUpdate" + rowCount).value.toLowerCase() == "true";
            if (document.getElementById("ctl00_ContentPlaceHolder3_FieldUpdateField" + rowCount).value == "")
                document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdate").selectedIndex = 0;
            else
                document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdate").value = document.getElementById("ctl00_ContentPlaceHolder3_FieldUpdateField" + rowCount).value;
            document.getElementById("ctl00_ContentPlaceHolder3_chkFieldUpdateReject").checked = document.getElementById("ctl00_ContentPlaceHolder3_addFieldUpdateReject" + rowCount).value.toLowerCase() == "true";
            document.getElementById("ctl00_ContentPlaceHolder3_txtFieldValueReject").value = document.getElementById("ctl00_ContentPlaceHolder3_FieldUpdateValueReject" + rowCount).value;
            if (document.getElementById("ctl00_ContentPlaceHolder3_FieldUpdateFieldReject" + rowCount).value == "")
                document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdateReject").selectedIndex = 0;
            else
                document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdateReject").value = document.getElementById("ctl00_ContentPlaceHolder3_FieldUpdateFieldReject" + rowCount).value;
            if (document.getElementById("ctl00_ContentPlaceHolder3_ddObject").value == "")
                document.getElementById("rdField").disabled = true;
            
            //Added by John Sathish    
            document.getElementById("ctl00_ContentPlaceHolder3_cbxAppEmail").checked = document.getElementById("ctl00_ContentPlaceHolder3_addFieldEmail" + rowCount).value.toLowerCase() == "true";
            //alert(document.getElementById("ctl00_ContentPlaceHolder3_FieldEmailTemplate" + rowCount).value);
            if (document.getElementById("ctl00_ContentPlaceHolder3_cbxAppEmail").checked)
                document.getElementById("ctl00_ContentPlaceHolder3_ddlAppEmail").value = document.getElementById("ctl00_ContentPlaceHolder3_FieldEmailTemplate" + rowCount).value;
            else{
                document.getElementById("ctl00_ContentPlaceHolder3_ddlAppEmail").disabled = true;
                document.getElementById("ctl00_ContentPlaceHolder3_ddlAppEmail").value = "";}
                
            document.getElementById("ctl00_ContentPlaceHolder3_cbxRejEmail").checked = document.getElementById("ctl00_ContentPlaceHolder3_addFieldEmailRej" + rowCount).value.toLowerCase() == "true";
            if (document.getElementById("ctl00_ContentPlaceHolder3_cbxRejEmail").checked)
                document.getElementById("ctl00_ContentPlaceHolder3_ddlRejEmail").value = document.getElementById("ctl00_ContentPlaceHolder3_FieldEmailTemplateRej" + rowCount).value;
            else{
                document.getElementById("ctl00_ContentPlaceHolder3_ddlRejEmail").disabled = true;
                document.getElementById("ctl00_ContentPlaceHolder3_ddlRejEmail").value = "";}
            //Up to this
            /*else
                document.getElementById("rdField").disabled = false;*/

            document.getElementById("ctl00_ContentPlaceHolder3_btnRuleSaveUpdate").value = "Save";
         }
        catch(Ex)
        {
            //alert(Ex.message); // Commented by srivatsan
        }
        open1();
        //return false;
    }
    
    function makeDropDownInvisible()
    {
        try
        {
            var arrlstCombos = new Array(11);
            arrlstCombos[0] = "ctl00_ContentPlaceHolder3_ddlbased_on";
            arrlstCombos[1] = "ctl00_ContentPlaceHolder3_ddObject";
            arrlstCombos[2] = "ctl00_ContentPlaceHolder3_ddEvent";
            arrlstCombos[3] = "ctl00_ContentPlaceHolder3_ddField1";
            arrlstCombos[4] = "ctl00_ContentPlaceHolder3_ddOperator1";
            arrlstCombos[5] = "ctl00_ContentPlaceHolder3_ddand_or1";
            arrlstCombos[6] = "ctl00_ContentPlaceHolder3_ddField2";
            arrlstCombos[7] = "ctl00_ContentPlaceHolder3_ddOperator2";
            arrlstCombos[8] = "ctl00_ContentPlaceHolder3_ddand_or2";
            arrlstCombos[9] = "ctl00_ContentPlaceHolder3_ddField3";
            arrlstCombos[11] = "ctl00_ContentPlaceHolder3_ddand_or3";
            arrlstCombos[10] = "ctl00_ContentPlaceHolder3_ddOperator3";
            
            
            for(iCount = 0; iCount < arrlstCombos.length; iCount++)
            {
                var ctrl = document.getElementById(arrlstCombos[iCount]);
                ctrl.style.visibility = "hidden";
            }
        }
        
        catch (Ex)
        {
            //alert(Ex.message); // Commented by srivatsan
        }
    }
    
    function makeDropDownVisible()
    {
        try
        {
            var arrlstCombos = new Array(12);
            arrlstCombos[0] = "ctl00_ContentPlaceHolder3_ddlbased_on";
            arrlstCombos[1] = "ctl00_ContentPlaceHolder3_ddObject";
            arrlstCombos[2] = "ctl00_ContentPlaceHolder3_ddEvent";
            arrlstCombos[3] = "ctl00_ContentPlaceHolder3_ddField1";
            arrlstCombos[4] = "ctl00_ContentPlaceHolder3_ddOperator1";
            arrlstCombos[5] = "ctl00_ContentPlaceHolder3_ddand_or1";
            arrlstCombos[6] = "ctl00_ContentPlaceHolder3_ddField2";
            arrlstCombos[7] = "ctl00_ContentPlaceHolder3_ddOperator2";
            arrlstCombos[8] = "ctl00_ContentPlaceHolder3_ddand_or2";
            arrlstCombos[9] = "ctl00_ContentPlaceHolder3_ddField3";
            arrlstCombos[10] = "ctl00_ContentPlaceHolder3_ddOperator3";
            arrlstCombos[11] = "ctl00_ContentPlaceHolder3_ddand_or3";
            for(iCount = 0; iCount < arrlstCombos.length; iCount++)
            {
                var ctrl = document.getElementById(arrlstCombos[iCount]);
                ctrl.style.visibility = "visible";
            }
        }
        
        catch (Ex)
        {
            //alert(Ex.message); // Commented by srivatsan
        }
    }
    
    function makeDropDownVisible()
    {
        try
        {
            var arrlstCombos = new Array(12);
            arrlstCombos[0] = "ctl00_ContentPlaceHolder3_ddlbased_on";
            arrlstCombos[1] = "ctl00_ContentPlaceHolder3_ddObject";
            arrlstCombos[2] = "ctl00_ContentPlaceHolder3_ddEvent";
            arrlstCombos[3] = "ctl00_ContentPlaceHolder3_ddField1";
            arrlstCombos[4] = "ctl00_ContentPlaceHolder3_ddOperator1";
            arrlstCombos[5] = "ctl00_ContentPlaceHolder3_ddand_or1";
            arrlstCombos[6] = "ctl00_ContentPlaceHolder3_ddField2";
            arrlstCombos[7] = "ctl00_ContentPlaceHolder3_ddOperator2";
            arrlstCombos[8] = "ctl00_ContentPlaceHolder3_ddand_or2";
            arrlstCombos[9] = "ctl00_ContentPlaceHolder3_ddField3";
            arrlstCombos[10] = "ctl00_ContentPlaceHolder3_ddOperator3";
            arrlstCombos[11] = "ctl00_ContentPlaceHolder3_ddand_or3";
            
            for(iCount = 0; iCount < arrlstCombos.length; iCount++)
            {
                var ctrl = document.getElementById(arrlstCombos[iCount]);
                ctrl.style.visibility = "visible";
            }
        }
        
        catch (Ex)
        {
            //alert(Ex.message); //Commented by srivatsan
        }
    }
    
    function DDForDivInvisible()
    {
        try
        {
            var arrlstCombos = new Array(9);
            arrlstCombos[0] = "ctl00_ContentPlaceHolder3_ddOperator1";
            arrlstCombos[1] = "ctl00_ContentPlaceHolder3_ddand_or1";
            arrlstCombos[2] = "ctl00_ContentPlaceHolder3_ddOperator2";
            arrlstCombos[3] = "ctl00_ContentPlaceHolder3_ddand_or2";
            arrlstCombos[4] = "ctl00_ContentPlaceHolder3_ddOperator3";            
            arrlstCombos[5] = "ctl00_ContentPlaceHolder3_ddand_or3";
            arrlstCombos[6] = "ctl00_ContentPlaceHolder3_ddOperator4";
            arrlstCombos[7] = "ctl00_ContentPlaceHolder3_ddand_or4";
            arrlstCombos[8] = "ctl00_ContentPlaceHolder3_ddOperator5";
            
            for(iCount = 0; iCount < arrlstCombos.length; iCount++)
            {
                var ctrl = document.getElementById(arrlstCombos[iCount]);
                ctrl.style.visibility = "hidden";
            }
        }
        
        catch (Ex)
        {
            //alert(Ex.message); //Comment by srivatsan
        }
    }
    
    function DDForDivVisible()
    {
        try
        {
            var arrlstCombos = new Array(9);
            arrlstCombos[0] = "ctl00_ContentPlaceHolder3_ddOperator1";
            arrlstCombos[1] = "ctl00_ContentPlaceHolder3_ddand_or1";
            arrlstCombos[2] = "ctl00_ContentPlaceHolder3_ddOperator2";
            arrlstCombos[3] = "ctl00_ContentPlaceHolder3_ddand_or2";
            arrlstCombos[4] = "ctl00_ContentPlaceHolder3_ddOperator3";            
            arrlstCombos[5] = "ctl00_ContentPlaceHolder3_ddand_or3";
            arrlstCombos[6] = "ctl00_ContentPlaceHolder3_ddOperator4";
            arrlstCombos[7] = "ctl00_ContentPlaceHolder3_ddand_or4";
            arrlstCombos[8] = "ctl00_ContentPlaceHolder3_ddOperator5";
            
            for(iCount = 0; iCount < arrlstCombos.length; iCount++)
            {
                var ctrl = document.getElementById(arrlstCombos[iCount]);
                ctrl.style.visibility = "visible";
            }
        }
        
        catch (Ex)
        {
            //alert(Ex.message); //Commented by srivatsan
        }
    }
    
    function AddRules()
    {
        //alert(rowCount);
        try
        {
            //Added by John Sathish  
            ddlEnableDisable("App");
            ddlEnableDisable("Rej");
            //Up to this  
            makeDropDownInvisible();
            document.getElementById("validateSpan").innerHTML = "";
            document.getElementById("ctl00_ContentPlaceHolder3_hfRule_Af_row_id").value ="";
            document.getElementById("ctl00_ContentPlaceHolder3_txtRuleName").value = "";
            document.getElementById("ctl00_ContentPlaceHolder3_hf_Target").value = "title";

            //if (document.getElementById("ctl00_ContentPlaceHolder3_hf_RowCount").value != "0")
                //document.getElementById("rdField").disabled = false;

            if (document.getElementById("ctl00_ContentPlaceHolder3_ddlbased_on").value == "Title")
            {
                /*if (document.getElementById("ctl00_ContentPlaceHolder3_hf_RowCount").value != "0")
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceTitle").disabled=true;    */
                document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceTitle").value = "";
            //document.getElementById("rdUser").disabled = true;
            //document.getElementById("ctl00_ContentPlaceHolder3_ddlTargetTitle").value = "";
            }
            else if (document.getElementById("ctl00_ContentPlaceHolder3_ddlbased_on").value == "User")
            {
                /*if (document.getElementById("ctl00_ContentPlaceHolder3_hf_RowCount").value != "0")
                    document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceUser").disabled=true;    */
                document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceUser").value = "";
            //document.getElementById("rdTitle").disabled = true;
            //document.getElementById("rdField").disabled = true;
            }
            document.getElementById("ctl00_ContentPlaceHolder3_txtWI_Message").value = "";
            document.getElementById("ctl00_ContentPlaceHolder3_txtFieldValue").value = "";
            document.getElementById("ctl00_ContentPlaceHolder3_chkAddWI").checked = true;
            document.getElementById("ctl00_ContentPlaceHolder3_chkFieldUpdate").checked = false;
            document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdate").value = "";            
            document.getElementById("ctl00_ContentPlaceHolder3_txtFieldValueReject").value = "";
            document.getElementById("ctl00_ContentPlaceHolder3_chkFieldUpdateReject").checked = false;
            document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdateReject").value = "";            
            document.getElementById("ctl00_ContentPlaceHolder3_btnRuleSaveUpdate").value = "Save";
            // Added by John Sathish to Implement Workflow Email functionality
            document.getElementById("ctl00_ContentPlaceHolder3_cbxAppEmail").checked = false;
            document.getElementById("ctl00_ContentPlaceHolder3_ddlAppEmail").value = "";     
            document.getElementById("ctl00_ContentPlaceHolder3_cbxRejEmail").checked = false;
            document.getElementById("ctl00_ContentPlaceHolder3_ddlRejEmail").value = "";     
            // upto this  
            document.getElementById("rdTitle").checked = true;
            document.getElementById("rdUser").checked = false;
            document.getElementById("rdField").checked = false;
            clearSelect();
            var splitTitle = document.getElementById("ctl00_ContentPlaceHolder3_hf_Title").value.split(",");
            document.getElementById("selTargetTitle").options[0] = new Option("--Select a title--","");
            for(iCount = 1; iCount < splitTitle.length ; iCount++)
            {
                document.getElementById("selTargetTitle").options[iCount] = new Option(splitTitle[iCount - 1],iCount);
            }
            
            if (document.getElementById("ctl00_ContentPlaceHolder3_ddObject").value == "")
            {
                document.getElementById("rdField").disabled = true;
            }
            /*else
            {
                document.getElementById("rdField").disabled = false;
            }*/
        }
        catch(Ex)
        {
            //alert(Ex.message); //Commented by srivatsan
        }
        open1();
        //return false;
    }
    function DeleteRules(strValue,afRowId)
    {
        if (confirm("Are you sure you want to delete the rule: " + strValue))
        {
            document.getElementById("ctl00_ContentPlaceHolder3_hfRule_delete").value = afRowId;        
            return true;
        }
        else
        {
            document.getElementById("ctl00_ContentPlaceHolder3_hfRule_delete").value = "";        
            return false;
        }
    }
    
    function setTitle(title)
    {
        document.getElementById("ctl00_ContentPlaceHolder3_txt" + title).value = document.getElementById("ctl00_ContentPlaceHolder3_dd" + title).value
    }
    
    function checkTitle(title)
    {
    try
    {
        var title_val = document.getElementById(title).value.toLowerCase();
        var all_title = document.getElementById("ctl00_ContentPlaceHolder3_hf_Title").value.toLowerCase();
        if (all_title.indexOf(title_val + ",") == -1)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    catch(Ex)
    {
    //alert(Ex.message);
    }
    }
    function wrapItAsMessage(strMessage)
    {
        return "<div class='mbErrorMessage'>" + strMessage + "</div>";
    }
    function validate()
    {
    
    //alert("inside validate");
    
        try
        {
////        if(document.getElementById("validateSpan")!=null)
////        {
////            document.getElementById("validateSpan").innerText = "";
////            document.getElementById("validateSpan").firstChild.nodeValue = "";    
////        }
        
            if (document.getElementById("ctl00_ContentPlaceHolder3_txtRuleName").value=="")
            {
            
            //alert("txtRuleName");
            if(document.getElementById("validateSpan")!=null)
            {
            //alert("control found");
            }
                //document.getElementById("validateSpan").innerText = "Rule Name is a mandatory Field.";
                document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Rule Name is a mandatory Field.");
                
                //document.getElementById("validateSpan").firstChild.nodeValue = "Rule Name is a mandatory Field.";
                return false;
            }
            
            if (document.getElementById("ctl00_ContentPlaceHolder3_ddlbased_on").value == "Title")
            {
                //if (document.getElementById("ctl00_ContentPlaceHolder3_hf_RowCount").value == "0")
                //{
                    if (document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceTitle").value == "")
                    {
                        document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Source Title is a mandatory Field.");
                        //document.getElementById("validateSpan").innerText = "Source Title is a mandatory Field.";
                        //document.getElementById("validateSpan").firstChild.nodeValue = "Source Title is a mandatory Field.";
                        return false;
                    }
                //}
                
                if (document.getElementById("selTargetTitle").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Target Title is a mandatory Field.");
                    //document.getElementById("validateSpan").innerText = "Target Title is a mandatory Field.";
                    //document.getElementById("validateSpan").firstChild.nodeValue = "Target Title is a mandatory Field.";
                    return false;
                }
            }
            else if (document.getElementById("ctl00_ContentPlaceHolder3_ddlbased_on").value == "User")
            {
            
            //alert("user based");
                //if (document.getElementById("ctl00_ContentPlaceHolder3_hf_RowCount").value == "0")
                //{
                    if (document.getElementById("ctl00_ContentPlaceHolder3_ddlSourceUser").value == "")
                    {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Source User is a mandatory Field.");
                        //document.getElementById("validateSpan").innerText = "Source User is a mandatory Field.";
                        //document.getElementById("validateSpan").firstChild.nodeValue = "Source User is a mandatory Field.";
                        return false;
                    }
               // }
                
                if (document.getElementById("selTargetTitle").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Target User is a mandatory Field.");
                    //document.getElementById("validateSpan").innerText = "Target User is a mandatory Field.";
                    //document.getElementById("validateSpan").firstChild.nodeValue = "Target User is a mandatory Field.";
                    return false;
                }            
            }
            
            if (document.getElementById("ctl00_ContentPlaceHolder3_chkAddWI").checked == false)
            { 
                document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Work Item Message is a mandatory Field.");
                //document.getElementById("validateSpan").innerText = "Work Item Message is a mandatory Field.";
                //document.getElementById("validateSpan").firstChild.nodeValue = "Work Item Message is a mandatory Field.";
                return false;
            }
            
            //if (document.getElementById("ctl00_ContentPlaceHolder3_chkAddWI").checked == true)
            //{ 
                if (document.getElementById("ctl00_ContentPlaceHolder3_txtWI_Message").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Work Item Message is a mandatory Field.");
                    //document.getElementById("validateSpan").innerText = "Work Item Message is a mandatory Field.";
                    //document.getElementById("validateSpan").firstChild.nodeValue = "Work Item Message is a mandatory Field.";
                    return false;
                }
            //}
            if (document.getElementById("ctl00_ContentPlaceHolder3_chkFieldUpdate").checked == true)
            {
                if (document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdate").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Select a field to be updated on approve.");
                    //document.getElementById("validateSpan").innerText = "Select a field to be updated on approve.";
                    //document.getElementById("validateSpan").firstChild.nodeValue = "Select a field to be updated on approve.";
                    return false;
                }
                if (document.getElementById("ctl00_ContentPlaceHolder3_txtFieldValue").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Specify a value to update the field on approve.");
                    //document.getElementById("validateSpan").innerText = "Specify a value to update the field on approve.";
                    //document.getElementById("validateSpan").firstChild.nodeValue = "Specify a value to update the field on approve.";
                    return false;
                }
            }
            if (document.getElementById("ctl00_ContentPlaceHolder3_chkFieldUpdateReject").checked == true)
            {
                if (document.getElementById("ctl00_ContentPlaceHolder3_ddFieldsUpdateReject").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Select a field to be updated on reject.");
                    //document.getElementById("validateSpan").innerText = "Select a field to be updated on reject.";
                    //document.getElementById("validateSpan").firstChild.nodeValue = "Select a field to be updated on reject.";
                    return false;
                }
                if (document.getElementById("ctl00_ContentPlaceHolder3_txtFieldValueReject").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Specify a value to update the field on reject.");
                    //document.getElementById("validateSpan").innerText = "Specify a value to update the field on reject.";
                    //document.getElementById("validateSpan").firstChild.nodeValue = "Specify a value to update the field on reject.";
                    return false;
                }
            }
            if (!(document.getElementById("ctl00_ContentPlaceHolder3_chkAddWI").checked || document.getElementById("ctl00_ContentPlaceHolder3_chkFieldUpdate").checked))
            {
                document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Select atleast one Workflow Action");
                //document.getElementById("validateSpan").innerText = "Select atleast one Workflow Action";
                //document.getElementById("validateSpan").firstChild.nodeValue = "Select atleast one Workflow Action";
                return false;
            }
            
            //Added by John Sathish
            if (document.getElementById("ctl00_ContentPlaceHolder3_cbxAppEmail").checked)
            {
            //alert(document.getElementById("ctl00_ContentPlaceHolder3_ddlAppEmail").value);
                if (document.getElementById("ctl00_ContentPlaceHolder3_ddlAppEmail").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Select E-Mail Template");
                    return false;
                }
            }
            
            if (document.getElementById("ctl00_ContentPlaceHolder3_cbxRejEmail").checked)
            {
                if (document.getElementById("ctl00_ContentPlaceHolder3_ddlRejEmail").value == "")
                {
                    document.getElementById("validateSpan").innerHTML = wrapItAsMessage("Select E-Mail Template");
                    return false;
                }
            }
            // Up to this
            document.getElementById("ctl00_ContentPlaceHolder3_hf_TargetSelected").value = document.getElementById("selTargetTitle").options[document.getElementById("selTargetTitle").value].text;
            
            disableThis("ctl00_ContentPlaceHolder3_btnSave","Save");
            disableThis("ctl00_ContentPlaceHolder3_btnUpdate","Save");
            disableThis("ctl00_ContentPlaceHolder3_btnReset","Reset");
            disableThis("ctl00_ContentPlaceHolder3_btnAddRule","Add New Rule");
            
            //alert("end");
        }
        catch(Ex)
        {
            //alert(Ex.Message); //Commented by srivatsan
        }
        close1();
        return true;   
    }
    
    function clearSelect()
    {
        try
        {
            if (document.getElementById("selTargetTitle").options.length == 0) return;

            var iTot = document.getElementById("selTargetTitle").options.length;

            var iCount;
            var selTarg = document.getElementById("selTargetTitle");
            iCount = iTot - 1
            for(iCount = iTot - 1; iCount >= 0; iCount--)
            {
                selTarg.removeChild(selTarg[iCount]);
            }
        }
            
        catch(Ex)
        {
            //alert(Ex.Message); //Commented by srivatsan
        }
    }
    
    function checkSelected(SelVal)
    {
        try
        {
        //alert(SelVal);
            if (document.getElementById("selTargetTitle").options.length == 0) return false;
            
            for(iCount = 0; iCount <= document.getElementById("selTargetTitle").options.length; iCount++)
            {
                //alert(document.getElementById("selTargetTitle").options[iCount].text);
                if (document.getElementById("selTargetTitle").options[iCount].text == SelVal)
                    return true;
            }
        }
        
        catch(Ex)
        {
            return false;
        }
        return true;
    }
    
    function SelectTarget(radio)
    {
        try
        {
            if (radio == "rdTitle")
            {
                document.getElementById("ctl00_ContentPlaceHolder3_hf_Target").value = "title";
                if (document.getElementById("selTargetTitle").options[0].text == "--Select a title--") return;
                //if(document.getElementById("rdTitle").checked) return;
                document.getElementById("rdTitle").checked = true;
                document.getElementById("rdUser").checked = false;
                document.getElementById("rdField").checked = false;
                clearSelect();

                var splitTitle = document.getElementById("ctl00_ContentPlaceHolder3_hf_Title").value.split(",");
                document.getElementById("selTargetTitle").options[0] = new Option("--Select a title--","");

                for(iCount = 1; iCount < document.getElementById("selTargetTitle").options.length; iCount++)
                {
                    document.getElementById("selTargetTitle").options[iCount] = null;
                }
                
                for(iCount = 1; iCount < splitTitle.length; iCount++)
                {
                    document.getElementById("selTargetTitle").options[iCount] = new Option(splitTitle[iCount-1],iCount);
                }
            }
            else if (radio == "rdUser")
            { 
                document.getElementById("ctl00_ContentPlaceHolder3_hf_Target").value = "user";
                if (document.getElementById("selTargetTitle").options[0].text=="--Select an user--") return;
                //if(document.getElementById("rdUser").checked) return;
                document.getElementById("rdTitle").checked = false;
                document.getElementById("rdUser").checked = true;
                document.getElementById("rdField").checked = false;
                clearSelect();
                var splitTitle = document.getElementById("ctl00_ContentPlaceHolder3_hf_User").value.split(",");
                document.getElementById("selTargetTitle").options[0] = new Option("--Select an user--","");
                
                for(iCount = 1; iCount < document.getElementById("selTargetTitle").options.length; iCount++)
                {
                    document.getElementById("selTargetTitle").options[iCount] = null;
                }
                for(iCount = 1; iCount < splitTitle.length; iCount++)
                {
                    document.getElementById("selTargetTitle").options[iCount] = new Option(splitTitle[iCount-1],iCount);
                }
            }
            else if (radio == "rdField")
            {
                document.getElementById("ctl00_ContentPlaceHolder3_hf_Target").value = "user_from_field";
                if (document.getElementById("selTargetTitle").options[0].text == "--Select a field--") return;
                //if(document.getElementById("rdField").checked) return;
                document.getElementById("rdTitle").checked = false;
                document.getElementById("rdUser").checked = false;
                document.getElementById("rdField").checked = true;
                var splitTitle = document.getElementById("ctl00_ContentPlaceHolder3_hf_Field").value.split(",");
                
                document.getElementById("selTargetTitle").options[0] = new Option("--Select a field--","");
                //alert("splittitle length : " + splitTitle.length);
                //alert("options length : " + document.getElementById("selTargetTitle").options.length);
                for(iCount = 1; iCount < document.getElementById("selTargetTitle").options.length; iCount++)
                {
                document.getElementById("selTargetTitle").options[iCount] = null;
                }
                //alert("options length : " + document.getElementById("selTargetTitle").options.length);
                for(iCount = 1; iCount < splitTitle.length; iCount++)
                {
                    document.getElementById("selTargetTitle").options[iCount] = new Option(splitTitle[iCount-1],iCount);
                }
                //alert("options length : " + document.getElementById("selTargetTitle").options.length);
            }
        }
        catch(Ex)
        {
            //alert("err : " + Ex.message);//Commented by srivatsan
        }
    }
 